new Vue({
    el: '#app',
    data() {
        return {
            form: {
                Store_SerialNumber: '',
                Store_Name: '',//供应商名称
                Opened_Date: '',//所属地址
                Closed_Date:'',
                Store_Address:'',
                Store_Type:'0',
                Store_SubType:'',
                Enterprise_Info_SerialNumber: '',
                address:'',
            },
            SubType:[{
                label:'天猫店',
                value:'0'
            },{
                label:'抖音店',
                value:'1'
            },{
                label:'美团店',
                value:'2'
            },{
                label:'大众点破',
                value:'3'
            },{
                label:'京东',
                value:'4'
            },{
                label:'小程序',
                value:'5'
            }],
            page: {
                page: 1,
                limit: 10,
            },
            value: [],
            address: '',
            rules: {
                Store_Name: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
                address: [{ required: true, message: '请输入详细地址', trigger: 'blur' }],
            },
            city: [],
            loading: false,
        }
    },
    mounted() {
        this.getData();
    },
    methods: {
        getData() {
            const that = this;
            $.ajax({
                url: absolutepath() + "utils/city.json",
                type: "GET",
                success: function (data) {
                    that.city = data
                },
                dataType: "json"
            })
        },
        submitForm(formName) {
            const that = this
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    that.loading = true;
                    that.form.Opened_Date = getYMDHMSDate();
                    that.form.Store_Address = that.form.Store_Type=='0'?`${that.value[0]}/${that.value[1]}/${that.value[2]}/${that.form.address}`:''
                    $.ajax({
                        headers: requestHeaders(),
                        url: `${BASE_URL2}/generalBusiness/generalSave`,
                        type: 'POST',
                        data: {
                            Data: JSON.stringify({ Add: { 
                                business_store_info: [that.form],
                                base_operation_log:[generateLog('添加店铺信息', '平台端操作', 'business_store_info', JSON.stringify({ Add: { business_store_info: [that.form] } }))] } 
                            })
                        },
                        success: function (res) {
                            if (res.Status === 'success') {
                                that.$message.success("提交成功")
                                window.history.go(-1)
                            } else {
                                that.$message.error("提交失败，请稍后再试")
                            }
                        },
                        complete: function (XMLHttpRequest) {
                            that.loading = false
                            requestPretreatment(XMLHttpRequest);//config/config.js 响应预检
                        },
                        dataType: "json"
                    })
                } else {
                    that.$message({
                        message: sumberError,
                        type: 'warning'
                    })
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
    }
})